﻿using BaseUtils.Helper;
using Service.src.Flow.Server;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;

namespace Service.src.Flow.Api
{

    public class SysDeviceApi
    {
        public static SysDriverServer driverServer;

        public SysDeviceApi()
        {
            driverServer = new SysDriverServer();
        }

        /// <summary>
        /// 添加设备，更新设备
        /// </summary>
        /// <param name="DriveJson"></param>
        /// <returns></returns>
        //public string AddDrive(string DeviceJson)
        //{
        //    SysDevicrInfo plcDriveInfo = ConvertHelper.ToObject<SysDevicrInfo>(DeviceJson);
        //    if (plcDriveInfo != null && plcDriveInfo.Id > 0 && !string.IsNullOrEmpty(plcDriveInfo.Id.ToString()))
        //    {
        //        driverServer.UpldateDrive(plcDriveInfo);
        //    }
        //    else
        //    {
        //        plcDriveInfo = driverServer.AddDrive(SqliteHelper.SystemDefaultDBID, plcDriveInfo);
        //    }

        //    return plcDriveInfo.ToJson();
        //}

        /// <summary>
        /// 根据 ID 删除设备
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        //public bool DeleteDriver(int Id)
        //{
        //    return driverServer.DeleteDriver(SqliteHelper.SystemDefaultDBID, Id);
        //}

     
        /// <summary>
        /// 根据 ID 获取设备详情数据
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
  
        //public string GetConnectedClients(int ServerId)
        //{
        //    EventServer Event = new EventServer();
        //    List<TcpClient> Clients = Event.GetConnectedClients(ServerId);
        //    List<string> ips = new List<string>();
        //    foreach (TcpClient item in Clients)
        //    {
        //        ips.Add(((IPEndPoint)item.Client.RemoteEndPoint).Address.ToString());
        //    }

        //    return ips.ToJson();
        //}

        public bool SendMessage(int ServerId, int ClientIndex, string Message)
        {
            EventServer Event = new EventServer();
            return Event.SendMessage(ServerId, ClientIndex, Message);
        }
    }
}
